home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1994 December
/
PSL Monthly Shareware CD-ROM (Public Software Library)(December 1994).bin
/
prgmming
/
dos
/
pascal4
/
pas1.art
< prev
next >
Wrap
Text File
|
1991-10-19
|
10KB
|
214 lines
Turbo Pascal is a language which has had many faces. Since
Borland introduced it in 1982 it has been everything from a purely
teaching language to the high power Turbo Pascal we know today. But,
the makers of Turbo Pascal have not forgotten its roots. Today, Turbo
Pascal can be used in writing the simplest application to the most
complex high-speed parrallel processing network applications.
The program below illustrates how easy it is to use Turbo Pascal
to writing a seemingly complex application. The code is for a program
much like the popular TheDraw~. This code took me less than 2 hours to
write and is less that 170 lines of code. With a few additions it could
easily rival any of the popular ANSI Drawing programs... some even like
TheDraw~ which have made their authors a pretty penny!
-----------> Beginning of Listing
Program ANSIPic; { The following code may be modified, changed and }
{ used in any way you wish. It may be distributed }
Uses CRT; { in whole or part and you do NOT have to credit }
{ OctagonSoft or Ben Shoval for the code }
const
UpArrow = #72; { These Constants are used to define cursor movements }
DnArrow = #80;
RtArrow = #77;
LtArrow = #75;
ColorUp = #73; { These are used to define the keys for changing colors }
ColorDn = #81;
BkColorUp = #71;
BkColorDn = #79;
SetDMKey = #50;
TRtCorner = #59; { These define the keys for drawing corners }
TLtCorner = #60;
BRtCorner = #61;
BLtCorner = #62;
ClrKey = #46; { Key to Clear the Screen }
var
DrawColor : Byte; { Stores the foreground color }
BKColor : Byte; { Stores the background color }
Ch : Char;
Procedure Setup;
Begin
TextMode(CO80); { Use 80 by 25 Text Mode }
HighVideo; { Use High Intensity Colors }
TextColor(White); { Set the starting Foreground color to White }
DrawColor := White; { Set the Foreground color variable }
TextBackground(Black); { Set the starting Background color to Black }
BKColor := Black; { Set the Background color variable }
ClrScr; { Clear the Screen }
GotoXY(1,1); { The Following sets up the screen }
Write('PgUp/PgGn Sets Color - Home/End Sets Background Color - ');
Write('<ALT>M Toggles Drawing');
GotoXY(1,25);
Write('Status: ');
GotoXY(25,25);
Write('Cursor Position: ');
GotoXY(60,25);
Write('F1 ',#218,' F2 ',#191,' F3 ',#192,' F4 ',#217);
GotoXY(40,12); { Put the cursor in the center of the screen }
End;
Procedure Draw;
Var
HiKey : Boolean; { Set to TRUE is the keypressed is an Extended Key }
DrawMode : Boolean; { Set to TRUE if in Drawing Mode }
PreX, PreY : Byte; { Used to hold X and Y when they are being written }
Begin
DrawMode := TRUE; { Always start out in Drawing Mode }
Repeat { Start of loop which exits with ESC or <ALT>X }
PreX := WhereX; { Get the current X pos }
PreY := WhereY; { Get the current Y pos }
GotoXY(42,25); { Go to 42,25 to write the current X and Y }
TextColor(White); { Writing will be done with White on Black }
TextBackground(Black);
Write('(',+PreX,+',',+PreY,+') '); { The spaces after then ) are needed }
GotoXY(9,25); { The Following write the Drawing Status }
if DrawMode = TRUE then Write('Drawing ') { Spaces are needed }
else Write('Not Drawing');
GotoXY(PreX, PreY); { Go back to where you were on the screen }
if DrawColor = BkColor then { Check that the foreground and background }
inc(DrawColor); { colors are not the same }
TextColor(DrawColor); { Set the Foreground color }
TextBackground(BKColor); { Set the Background color }
HiKey := False; { Always assume that it is NOT a Hi Key }
Ch := Readkey; { Read a key }
If Ch=#0 then { If it is a Hi Key (#0 was returned first) }
Begin
Ch := Readkey; { If we got here then it is a Hi Key }
HiKey := TRUE; { Set HiKey to TRUE }
End;
Case Ch Of
UpArrow : Begin { Routine if the Up Arrow was pressed }
GotoXY(WhereX,WhereY-1); { Move up a line }
if WhereY = 1 then GotoXY(WhereX,2); { make sure we're }
if DrawMode = True then { not on 1st line }
Begin { We're here if we're in drawing mode }
Write(#179);
GotoXY(WhereX-1,WhereY); { Move the cursor onto the }
End; { character which was drawn}
End;
DnArrow : Begin { Routine if the Down Arrow was pressed }
GotoXY(WhereX,WhereY+1); { Move down a line }
If WhereY = 25 then GotoXY(WhereX,24); { make sure we're }
if DrawMode = True then { not on 25th line}
Begin
Write(#179);
GotoXY(WhereX-1,WhereY); { Move the cursor onto the }
End; { character which was drawn}
End;
RtArrow : Begin { Routine if the Right Arrow was pressed }
GotoXY(WhereX+1,WhereY); { Move to the right one position }
if WhereX = 80 then GotoXY(79,WhereY); { make sure we're }
if DrawMode = True then { not in 79th spot}
Begin
Write(#196);
GotoXY(WhereX-1,WhereY); { Move the cursor onto the }
End; { character which was drawn}
End;
LtArrow : Begin { Routine if the Left Arrow was pressed }
GotoXY(WhereX-1,WhereY); { Move to the left one position }
if DrawMode = True then
Begin
Write(#196);
GotoXY(WhereX-1,WhereY); { Move the cursor onto the }
End; { character which was drawn}
End;
ColorUp : If DrawColor < 15 then inc(DrawColor) { Foreground colors }
else DrawColor := 0; { are from 0 to 15 }
ColorDn : If DrawColor > 0 then dec(DrawColor)
else DrawColor := 15;
BkColorUp : if BkColor < 15 then inc(BkColor) { Background colors }
else BkColor := 0; { are from 0 to 7 }
BkColorDn : if BkColor > 0 then dec(BkColor)
else BkColor := 15;
SetDMKey : If HiKey = TRUE then { make sure we have a Hi Key }
if DrawMode = TRUE then DrawMode := FALSE
else DrawMode := TRUE; { Toggle Draw Mode }
TRtCorner : if HiKey = TRUE then { Routine to Draw Top Right Corner }
begin
write(#218);
GotoXY(WhereX-1,WhereY);
end;
TLtCorner : if HiKey = TRUE then { Routine to Draw Top Left Corner }
begin
write(#191);
GotoXY(WhereX-1,WhereY);
end;
BRtCorner : if HiKey = TRUE then { Routine to Draw Bottom Right Corner }
begin
write(#192);
GotoXY(WhereX-1,WhereY);
end;
BLtCorner : if HiKey = TRUE then { Routine to Draw Bottom Left Corner }
begin
write(#217);
GotoXY(WhereX-1,WhereY);
end;
ClrKey : if HiKey = TRUE then Setup; { Clear the Screen }
#32..#136 : If HiKey = FALSE then { Routine to write an ASCII }
Begin { character to the screen }